package org.dynobjects.core;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.lang.StringUtils;

public class ResourceResolver {

	
	public InputStream resolve(String path) throws IOException{
		InputStream in = null;
		if(path.indexOf("classpath:")>=0){
			path = StringUtils.replace(path, "classpath:", "");
			if(!path.substring(0).equals("/")){
				path = "/"+path;
				in =  ResourceResolver.class.getResourceAsStream(path);
			}
		}
		if(path.indexOf("file:")>=0){
			path = StringUtils.replace(path, "file:", "");
			in = new FileInputStream(path);
		}
		return in;
	}
}
